import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { SnakeNamingStrategy } from '../../snake-naming.strategy';
import { envString, envNumber } from '../../config/index'; // 导入一个配置项
@Module({
  imports: [
    //同步配置mysql
    TypeOrmModule.forRoot({
      // type: 'mysql',
      // host: envString('MYSQL_HOST', '192.168.59.111'),
      // port: envNumber('MYSQL_PORT', 3306),
      // username: envString('MYSQL_USERNAME', 'root'),
      // password: envString('MYSQL_PASSWORD', 'root'),
      // database: envString('MYSQL_DATABASE', 'test'),
      type: 'mysql',
      host: '192.168.59.111',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'test',
      namingStrategy: new SnakeNamingStrategy(), //抄来的 驼峰转换处理
      // entities: [__dirname + '../../entities/*.entity{.ts,.js}'],  webpack 打包不认
      // synchronize: true, //不建议生产
      autoLoadEntities: true, //通过　TypeOrmModule.forFeature([User]　自动加载
    }),
  ],
  exports: [MysqlModule],
})
export class MysqlModule {}
